//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    imgList: [
      {
        id: "0001",
        imgUrl: "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg"
      },
      {
        id: "0002",
        imgUrl: "http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg"
      },
      {
        id: "0003",
        imgUrl: "http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg"
      }
    ],
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    indicatorDotsOne: false,
    autoplayOne: false,
    currentItem: 0,
    currentArea: '广州',
    indexNavList: [
      {
        id: "0001",
        imagesUrl: "../../images/index/party.png",
        title: "交谊会"
      },
      {
        id: "0002",
        imagesUrl: "../../images/index/consult.png",
        title: "情感咨询"
      }
    ],
    // 推荐列表
    recommendList: [
      {
        id: "0001",
        headImg: "../../images/index/01.jpg",
        name: "草莓妹妹",
        sex: 1,
        charmValue: 200,
        city: "广州",
        area: "天河",
        age: 24
      },
      {
        id: "0002",
        headImg: "../../images/index/02.jpg",
        name: "草莓妹妹",
        sex: 2,
        charmValue: 200,
        city: "广州",
        area: "白云",
        age: 24
      },
      {
        id: "0003",
        headImg: "../../images/index/02.jpg",
        name: "草莓妹妹",
        sex: 2,
        charmValue: 200,
        city: "广州",
        area: "白云",
        age: 24
      },
      {
        id: "0004",
        headImg: "../../images/index/01.jpg",
        name: "草莓妹妹",
        sex: 2,
        charmValue: 200,
        city: "广州",
        area: "白云",
        age: 24
      }
    ],
    // 附近列表
    nearbyList: [
      {
        id: "0001",
        headImg: "../../images/index/01.jpg",
        name: "草莓妹妹",
        sex: 1,
        charmValue: 200,
        city: "广州",
        area: "天河",
        age: 24,
		distance: 500
      },
	  {
		  id: "0002",
		  headImg: "../../images/index/02.jpg",
		  name: "草莓妹妹",
		  sex: 1,
		  charmValue: 200,
		  city: "广州",
		  area: "天河",
		  age: 24,
		  distance: 800
	  },
	  {
		  id: "0003",
		  headImg: "../../images/index/01.jpg",
		  name: "草莓妹妹",
		  sex: 1,
		  charmValue: 200,
		  city: "广州",
		  area: "天河",
		  age: 24,
		  distance: 500
	  },
	  {
		  id: "0004",
		  headImg: "../../images/index/01.jpg",
		  name: "草莓妹妹",
		  sex: 1,
		  charmValue: 200,
		  city: "广州",
		  area: "天河",
		  age: 24,
		  distance: 500
	  }
    ],
	indexContentNav: {
		index: 0,
		indexContenNavtLeftStyle: "index-content-navOne index-content-navLeft",
		indexContenNavtRightStyle: "index-content-navOne"
	}

  },
  
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  indexContentNavOne: function (){
	var that = this
	if (that.data.indexContentNav.index === 1){
		that.setData({
			indexContentNav: {
				index: 0,
				indexContenNavtLeftStyle: "index-content-navOne index-content-navLeft",
				indexContenNavtRightStyle: "index-content-navOne"
			}
		})
	}
  },
  indexContentNavTwo: function(){
	var that = this
	if (that.data.indexContentNav.index === 0){
		that.setData({
			indexContentNav: {
				index: 1,
				indexContenNavtLeftStyle: "index-content-navOne",
				indexContenNavtRightStyle: "index-content-navOne  index-content-navRight"
			}
		})
	}
	console.log(that.data.indexContentNav)
  },

  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
	
  },
  getUserInfo: function (e) {
    console.log(app.globalData);
    //保存用户信息
    wx.request({
      url: 'https://love.163ar.cn/api/user/saveuserinfo',
      method: 'POST',
      data: {
        userinfo: e.detail.userInfo,
        openid: app.globalData.openid,
      },
      success: function (res) {
        console.log(res);
      }
    })
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
